//
//  OERegisterDownViewController.m
//  OneEightyNine
//
//  Created by apple on 2019/3/3.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEFindPwdFirstViewController.h"
#import "OEFindPwdSecendViewController.h"
@interface OEFindPwdFirstViewController ()
@property(nonatomic, strong) UITextField                     *phoneTextFiled;/**<  */
@property(nonatomic, strong) STButton                     *nextButton;/**<  */
@end

@implementation OEFindPwdFirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubView];
    [self addregNotifacations];
    [self st_addAdjustView:self.nextButton offset:10];
    // Do any additional setup after loading the view.
}
- (void)addregNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(st_notifactionMethod:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:nil];
    
}
- (void)st_notifactionMethod:(NSNotification*)notifacation{
    if (notifacation.object == self.phoneTextFiled) {
        if (self.phoneTextFiled.text.length == 11) {
            self.nextButton.backgroundColor =OE_LIMITE_COLOR;
            self.nextButton.userInteractionEnabled = YES;
        }else{
            self.nextButton.backgroundColor =UIColor.grayColor;
            self.nextButton.userInteractionEnabled = NO;
        }
    }
    
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark --configSubView
- (void)configSubView{
    self.tableView.backgroundColor = UIColor.whiteColor;
    
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    
    STLabel * alertLabel = [[STLabel alloc] initWithFrame:CGRectMake(22, 20, UIScreenWidth - 44, 40)
                                                     text:OESTRING(@"FORGET THE PASSWORD")
                                                textColor:SecendTextColor
                                                     font:18
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [footer addSubview:alertLabel];
    
    self.phoneTextFiled =  [self textFiledWithLeftTitle:[NSString stringWithFormat:@"%@ >",OE_PHONE_PREFIX]
                                           placeHolader:OESTRING(@"Phone number") rightView:nil];
    self.phoneTextFiled.top = alertLabel.bottom + 65;
    self.phoneTextFiled.keyboardType = UIKeyboardTypeNumberPad;
    [footer addSubview:self.phoneTextFiled];
    
    __weak typeof(self) weakSelf =  self;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(5, self.phoneTextFiled.bottom + 80, UIScreenWidth - 30, 44)
                                                        title:OESTRING(@"NEXT")
                                                   titleColor:UIColor.whiteColor
                                                    titleFont:15
                                                 cornerRadius:22
                                              backgroundColor:UIColor.grayColor
                                              backgroundImage:nil
                                                        image:nil];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    confimButton.centerX = self.tableView.width / 2;
    [footer addSubview:confimButton];
    [confimButton setClicAction:^(UIButton *sender) {
        OEFindPwdSecendViewController * vc = OEFindPwdSecendViewController.new;
        vc.phone= weakSelf.phoneTextFiled.text;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    self.nextButton = confimButton;
    self.nextButton.userInteractionEnabled = NO;
    
    footer.height = self.nextButton.bottom;
    self.tableView.tableFooterView = footer;
}
- (UITextField*)textFiledWithLeftTitle:(NSString*)leftTitle placeHolader:(NSString*)placeHolader  rightView:(UIView*)rightView{
    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth-30, 50)];
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, textFiled.height, textFiled.height)
                                                     title:leftTitle
                                                titleColor:OE_LIMITE_COLOR
                                                 titleFont:14
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    if (leftTitle.length) {
        textFiled.leftView = buyButton;
    }
    
    textFiled.leftViewMode = UITextFieldViewModeAlways;
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    textFiled.placeholder = placeHolader;
    
    textFiled.rightView = rightView;
    textFiled.rightViewMode = UITextFieldViewModeAlways;
    [textFiled st_showBottomLine];
    return textFiled;
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
